package com.springapp.mvc.controller;

import com.springapp.mvc.tools.ZipDecompressing;
import org.springframework.stereotype.Controller;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.io.ByteArrayInputStream;

@Controller
@RequestMapping("/page")
public class PageUploadController {
    @RequestMapping(value = "/pageUpload.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String getApply(MultipartHttpServletRequest request, String id, String pageZip) {
        //TODO 添加apply_order
        String path = request.getSession().getServletContext().getRealPath("machine");

        byte[] data = Base64Utils.decodeFromString(pageZip);

        ByteArrayInputStream bais = new ByteArrayInputStream(data);

        ZipDecompressing.decompression(bais, path, "productDetail" + id + ".jsp");

        return "hello";//json
    }
}
